/*
** StockDB
**
** Copyright (C) 2012 - ? doublegsoft
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __STOCKDB_H__
#define __STOCKDB_H__

#define PORTSTR         "7017"
#define PORT            7017

#define SHANGHAI_DATAFILE        "shanghai.sdb"
#define SHENZHEN_DATAFILE        "shenzhen.sdb"

// errors
#define ERROR_NO_ERROR           0
#define ERROR_NO_STOCKS_FOUND   -1
#define ERROR_NO_STOCK_FOUND    -2

// how many pending connections queue will hold
#define BACKLOG         10

#define TRUE            '1'

#define FALSE           '0'

#ifdef __MACH__

typedef struct fd_set fd_set;

#endif

typedef unsigned int   uint;

typedef unsigned int   ulong;

typedef char           bool;


/*!
** It's stockdb data file header, including total stock size and first and last
** offset of stock data.
*/
typedef struct stocks_t
{
  uint  size;

  /*!
  ** first stock_t position.
  */
  ulong first;

  /*!
  ** last stock_t position.
  */
  ulong last;
}
stocks_t;

/*!
** Stock summary information.
*/
typedef struct stock_t
{
  /*!
  ** stock code.
  */
  char  code[6];

  /*!
  ** stock_daily_t data count.
  */
  uint  size;

  /*!
  ** first stock_daily_t position.
  */
  ulong first;

  /*!
  ** last stock_daily_t position.
  */
  ulong last;

  /*!
  ** next stock_t position.
  */
  ulong next;
}
stock_t;

/*!
** Stock daily transaction data.
*/
typedef struct stock_daily_t
{
  /*!
  ** transaction date stored as long like 20120315 (YYYYMMDD).
  */
  ulong time;

  /*!
  ** open price stored as integer like 10880 (= 10.88 * 1000).
  */
  uint  open;

  /*!
  ** closed price stored as integer like 10880 (= 10.88 * 1000).
  */
  uint  closed;

  /*!
  ** high price stored as integer like 10880 (= 10.88 * 1000).
  */
  uint  high;

  /*!
  ** low price stored as integer like 10880 (= 10.88 * 1000).
  */
  uint  low;

  /*!
  ** transaction volume as integer like 10000 (10000).
  */
  uint  volume;

  /*!
  ** transaction amount as integer like 1088000 (= 10880000 / 10).
  */
  uint  amount;

  /*!
  ** next stock_daily_t position in data file.
  */
  ulong next;
}
stock_daily_t;

#endif /* __STOCKDB_H__ */
